package com.lee.account.utils;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.util.UUID;

/**
 * 常用工具方法
 * @author liyou
 * @date 2019年9月3日 下午4:02:54
 */
public class StringUtil {

	/**
	 * UUID生成器
	 * @return
	 */
	public static String getUUID() {
		return UUID.randomUUID().toString().replaceAll("-", "");
	}
	
	/**
	 * 获取文件编码
	 * @param fileName
	 * @return
	 * @throws Exception
	 */
	public static String codeString(String fileName) throws Exception {
        BufferedInputStream bin = new BufferedInputStream(new FileInputStream(fileName));
        int p = (bin.read() << 8) + bin.read();
        bin.close();
        String code = null;
 
        switch (p) {
        case 0xefbb:
            code = "UTF-8";
            break;
        case 0xfffe:
            code = "Unicode";
            break;
        case 0xfeff:
            code = "UTF-16BE";
            break;
        default:
            code = "GBK";
        }
 
        return code;
    }
}
